//
//  LGSAndGate.m
//  LogicSim
//
//  Created by Jeremy Pereira on 04/04/2012.
//  Copyright (c) 2012 Jeremy Pereira. All rights reserved.
//

#import "LGSHexDigit.h"
#import "LGSEdge.h"
#import "LGSName.h"

@implementation LGSHexDigit
{
    int digit;
}

@synthesize digit;

-(TimeTick) gateDelay
{
    return 0;
}

-(void) evaluateAffectedNodes: (NSMutableOrderedSet*) affectedNodes
{
    int theDigit = [self digit];
    for (int bit = 0 ; bit < 4 ; ++bit)
    {
        LGSName* outputName = [[LGSName alloc] initWithNodePart: nil
                                                 connectionPart: @"bit"
                                                      nodeIndex: LGS_NAME_NO_INDEX
                                                connectionIndex: bit];
        NSSet* currentOutputs = [self outputsForName: outputName];
        bool theValue = (theDigit & (1 << bit)) != 0;
        for (LGSEdge* output in currentOutputs)
        {
            [output setValue: theValue affectedNodes: affectedNodes];
        }
    }
}

+(NSArray*) defaultOutputNames
{
    return @[[LGSName nameWithConnectionString: @"bit[0]"],
             [LGSName nameWithConnectionString: @"bit[1]"],
             [LGSName nameWithConnectionString: @"bit[2]"],
             [LGSName nameWithConnectionString: @"bit[3]"]];
}

@end
